package org.jcc.core.cs.functional;

public class PolymorphicSum {
	
	public static void main(String[] args) {
		int idSum = sum(new Identity());
		int sqSum = sum(new Square());
		int cbSum = sum(new Cube());
		
		System.out.println(idSum + " " + sqSum + " " + cbSum);
		
	}

	public static int sum(MyFunction f) {
		int sum = 0;
		for (int i = 1; i <= 100; i++) {
			sum += f.apply(i);
		}
		return sum;
	}
}

class Identity implements MyFunction {
	@Override
	public int apply(int i) {
		return i;
	}
}

class Square implements MyFunction {
	@Override
	public int apply(int i) {
		return i * i;
	}
}

class Cube implements MyFunction {
	@Override
	public int apply(int i) {
		return i * i * i;
	}
}
